
$(function() {	
	Tip.emp('员工');
});

var Arp = {

	popup: function (e, p2, id) {
		$.cookie('id_', id);

		p2 = query(p2);
		$.cookie('p2', p2);
		
		var c1 = 'log.php?do=Arp.edit&id=' + id;
		var c2 = 'log.php?do=Arp.copy&id=' + id;
		
		var c3 = 'log.php?do=Arp.add&id=' + id;

		var a1 = ['编辑信息', 'url', 'Arp.dialog_edit_', '650x420'];
		var a2 = ['复制信息', 'url', 'Arp.dialog_copy_', '650x420'];
		
		var a3 = ['分配员工', 'url', 'Arp.dialog_add_', '650x420'];

		var s = c1 + ", " + c2 + ", " + c3;
		
		popup(e, [a1, a2, a3], s);
	},

	dialog_edit_: function (url, title, xy) {
		var result = Common.result();
		$.getJSON('log.php?do=Arp.audit&item=80', function(json) {
			if (json.status == 1) {
				$('#dialog_edit').dialog('option', 'buttons', {			
					"关闭": function() {
						$(this).dialog("close");
					},
			
					"修改": function() {
						if (!confirm("确认是否提交？")) {
							return false;
						}
			
						var form = $("#form_edit")[0];
			
						var body = {};
						body.id = form.id.value;
			
						body.mac = form.mac.value;
						body.dhcp = form.dhcp.value;
			
						body.ip1 = form.ip1.value;
						body.ip2 = form.ip2.value;
			
						body.netmask = form.netmask.value;
			
						body.gw = form.gw.value;
						body.dns = form.dns.value;
						
						body.upload = form.upload.value;
						body.download = form.download.value;
						
						body.category = form.category.value;
						body.content = form.content.value;
						
						body.emp = form.emp.value;
						body.status = form.status.value;
			
						$(this).dialog("close");
			
						var url = 'log.php?do=Arp.editPost';
						var p2 = $.cookie('p2');
						if (p2 != null) {
							url += p2;
						}
			
						$.post(url, body, function(data) {
							$(result).html(data);
						});
					}
				});
			
				dialog_edit(url, title, xy);
			} else {
				_error();
			}
		});
	},
	
	dialog_add_: function (url, title, xy) {
		var result = Common.result();
		$.getJSON('log.php?do=Arp.audit&item=80', function(json) {
			if (json.status == 1) {
				$('#dialog_add').dialog('option', 'buttons', {			
					"关闭": function() {
						$(this).dialog("close");
					},
			
					"添加": function() {
						if (!confirm("确认是否提交？")) {
							return false;
						}
			
						var form = $("#form_add")[0];
			
						var body = {};						
			
						body.emp = form.emp.value;
						body.mac = form.mac.value;
						
						body.ip = form.ip.value;			
						body.netmask = form.netmask.value;			
						body.gw = form.gw.value;
						
						body.content = form.content.value;
									
						$(this).dialog("close");
			
						var url = 'log.php?do=Arp.addPost';
			
						$.post(url, body, function(data) {
							$(result).html(data);
						});
					}
				});
			
				dialog_add(url, title, xy);
			} else {
				_error();
			}
		});
	},

	dialog_copy_: function (url, title, xy) {
		var result = Common.result();
		$.getJSON('log.php?do=Arp.audit&item=80', function(json) {
			if (json.status == 1) {
				$('#dialog_add').dialog('option', 'buttons', {			
					"关闭": function() {
						$(this).dialog("close");
					},
			
					"复制": function() {
						if (!confirm("确认是否提交？")) {
							return false;
						}
			
						var form = $("#form_add")[0];
			
						var body = {};
						body.id = form.id.value;
			
						body.mac = form.mac.value;
						body.dhcp = form.dhcp.value;
			
						body.ip = form.ip.value;
						body.netmask = form.netmask.value;
			
						body.gw = form.gw.value;
						body.category = form.category.value;
						body.content = form.content.value;
						body.status = form.status.value;
			
						$(this).dialog("close");
			
						var url = 'log.php?do=Arp.copyPost';
						var p2 = $.cookie('p2');
						if (p2 != null) {
							url += p2;
						}
			
						$.post(url, body, function(data) {
							$('#dialog_add').html(data);
						});
					}
				});
			
				dialog_add(url, title, xy);
			} else {
				_error();
			}
		});
	}
};
